@title = "管理首页"

form class:"well form-horizontal", method:"POST", action:"/admin/invite/new/", ->
  fieldset ->
    div class:"control-group", ->
      label class:"control-label", "邀请码:"
      div class:"controls", ->
        textarea class:"input-xlarge", rows: 5, ->
          text (i.code for i in @invites).join "\n" if @invites.length > 0
    div class:"control-group", ->
      label class:"control-label", for:"emails", "生成邀请码:"
      div class:"controls", ->
        div class:"input-append", ->
          input type:"text", class:"input-medium", id:"invite_count", name:"invite_count", placeholder:"邀请码数量"
          button type:"submit", class:"btn btn-primary", "生成邀请码"

form class:"well form-horizontal", method:"POST", action:"/admin/invite/email/", ->
  fieldset ->
    div class:"control-group", ->
      label class:"control-label", for:"emails", "邀请指定用户:"
      div class:"controls", ->
        textarea class:"input-xlarge", id:"emails", name:"emails", rows: 4, placeholder:"soddyque@gmail.com,sallyzong@gmail.com"
    div class:"form-actions", ->
      button type:"submit", class:"btn btn-primary", "发送邀请"

form class:"well form-horizontal", method:"POST", action:"/admin/tag/new/", ->
  fieldset ->
    div class:"control-group", ->
      label class:"control-label", "标签:"
      div class:"controls", ->
        for i in @tags
          a href:"/#{i.url}", class:"btn btn-mini", "#{i.name}"
    div class:"control-group", ->
      label class:"control-label", for:"emails", "创建标签:"
      div class:"controls", ->
        #textarea class:"input-xlarge", id:"emails", name:"emails", rows: 4, placeholder:"soddyque@gmail.com,sallyzong@gmail.com"
        div class:"input-prepend", ->
          span class:"add-on", -> i class:"icon-tag"
          input type:"text", class:"input-medium", name:"name", placeholder:"标签名称"
        div class:"input-prepend input-append", ->
          span class:"add-on", -> i class:"icon-magnet"
          input type:"text", class:"input-medium", name:"url", placeholder:"标签URL"
          button type:"submit", class:"btn btn-primary", "创建标签"

form class:"well form-horizontal", method:"POST", action:"/admin/tag/hot/", ->
  fieldset ->
    div class:"control-group", ->
      label class:"control-label", for:"hottags", "热门标签:"
      div class:"controls", ->
        textarea class:"input-xlarge", id:"hottags", name:"hottags", rows: 4, placeholder:"标签名称,半角逗号分隔"
    div class:"form-actions", ->
      button type:"submit", class:"btn btn-primary", "提交修改"

coffeescript ->
  $("form[action='/admin/invite/new/']")
    .submit((e)->
      t = $(e.target)
      if !t.valid()
        return false
    ).validate
      rules:
        invite_count:
          required: true
          digits: true
      messages:
        invite_count:
          required: "邀请码必填"
          digits: "必须为数字"

  $("form[action='/admin/tag/new/']")
    .submit((e)->
      t = $(e.target)
      if !t.valid()
        return false
    ).validate
      rules:
        name:
          required: true
        url:
          required: true
      messages:
        name:
          required: "标签名称必填"
        url:
          required: "访问路径必填"
